 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
import { ETaskState } from "GameLoop/DecisionMaking/TaskDeclare/type";
import { priority } from "utils/constants/definetypes";
 

/**
 * PC任务决策
 */
export class powerCreepTask< T extends "pc"="pc"> extends ABaseDecision<T>
{
    public isExpired(event: PowerEvent, region: string): boolean 
    {
        const room = Game.rooms[event.region];
        if(event.ObjectID)
        {
            if(room.findTaskById(event.ObjectID,'pc'))
            {
                return false;
            }
        }
        
        return true;
    }
    public makeTask(event: PowerEvent, region: string): IDecisionCode<T>|false
    {
        const room = Game.rooms[event.region] as Required<Room>;
        room.log(`info`,`op Source Task`);
        const takeobject = room.getEntity("CoreEntity").getTakeStores({resourceType:RESOURCE_OPS,amount:100})[0];
        if(!takeobject)
        {
            room.log(`info`,`投递power任务`,"房间OPS 不足 生成任务失败");
            return false;
        }
        const powerTask:IPowerCreepData<"userPower">  = 
        {
            type: "userPower",
            arg: {
                POWER: event.POWER,
                ObjectID: event.ObjectID
            },
            OPSstoreId: takeobject.id,
            state: ETaskState.Running,
            room: event.room
        }
        // 
        const code:IDecisionCode<T>={
            region:event.region,
            isunique:false,
            task:[{
                id:event.ObjectID?event.ObjectID:`${event.room}_${event.POWER}`,
                priority:priority.C,
                ttl:5000,
                type:"pc",
                data:powerTask,
                shard:1,
            }],
        }
       
        return code;
    }
    
}